
from tools.handle_path import data_dir

import pprint
import openpyxl
from openpyxl import load_workbook

class HandleExcel:
    def __init__(self,file_name):
        #表对象
        self.wb_obj = load_workbook(filename=file_name)
        # #表单对象
        # self.sheet_obj = self.wb_obj[sheet_name]

    #获取表单数据,从start中拿到sheetname，每个sheet里边的数据
    def get_datas(self,sheet_name):
        try:
            data_list = []
            sheet_obj = self.wb_obj[sheet_name]
            test_list = list(sheet_obj.iter_rows(values_only=True))
            title = test_list[0]
            datas = test_list[1:]
            for val in datas:
                result = dict(zip(title,val))
                data_list.append(result)
            return data_list
        except Exception as e:
            print("报错了",e)

    # #获取表单数据
    # def get_datas(self):
    #     try:
    #         test_list = list(self.sheet_obj.iter_rows(values_only=True))
    #         data_list = []
    #         title = test_list[0]
    #         datas = test_list[1:]
    #         for val in datas:
    #             result = dict(zip(title,val))
    #             data_list.append(result)
    #         return data_list
    #     except Exception as e:
    #         print("报错了",e)
    #     finally:
    #         self.wb_obj.close()


